<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 2. High Level Components</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="concepts/objectwrapper.html" title="ObjectWrapper">
<link rel="next" href="high_level_components/boost_python_def_hpp.html" title="boost/python/def.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="concepts/objectwrapper.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="high_level_components/boost_python_def_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="high_level_components"></a>Chapter 2. High Level Components</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp">boost/python/class.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel">Class
        template <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Bases</span><span class="special">,</span> <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">NonCopyable</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn">Class
        template bases&lt;T1, T2, ...TN&gt;</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html">boost/python/def.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html">boost/python/def_visitor.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor">Class
        <code class="computeroutput"><span class="identifier">def_visitor</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html">boost/python/docstring_options.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options">Class
        <code class="computeroutput"><span class="identifier">docstring_options</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_dostring_options_construct">Class
        dostring_options constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_destruct">Class
        docstring_options destructor</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_modifier">Class
        <code class="computeroutput"><span class="identifier">docstring_options</span></code> modifier
        functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html">boost/python/enum.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum">Class
        template <code class="computeroutput"><span class="identifier">enum_</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_constructors">Class
        template <code class="computeroutput"><span class="identifier">enum_</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_modifier_fun">Class
        template <code class="computeroutput"><span class="identifier">enum_</span></code> modifier functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html">boost/python/errors.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set">Class
        <code class="computeroutput"><span class="identifier">error_already_set</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html">boost/python/exception_translator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.function_register_exception_tran">Function
        <code class="computeroutput"><span class="identifier">register_exception_translator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html">boost/python/init.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init">Class
        template <code class="computeroutput"><span class="identifier">init</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_optional">Class
        template <code class="computeroutput"><span class="identifier">optional</span></code> </a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html">boost/python/iterator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator">Class
        template <code class="computeroutput"><span class="identifier">iterator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator_construc">Class
        template iterator constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators">Class
        template <code class="computeroutput"><span class="identifier">iterators</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_nested_">Class
        template iterators nested types</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_static_">Class
        template iterators static functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html">boost/python/module.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html">boost/python/operators.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_self_ns_self_t">Class
        <code class="computeroutput"><span class="identifier">self_ns</span><span class="special">::</span><span class="identifier">self_t</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_template_other">Class
        template <code class="computeroutput"><span class="identifier">other</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_template_detail_operator">Class
        template <code class="computeroutput"><span class="identifier">detail</span><span class="special">::</span><span class="identifier">operator_</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.object_self">Object
        <code class="computeroutput"><span class="identifier">self</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html">boost/python/scope.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope">Class
        <code class="computeroutput"><span class="identifier">scope</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope_constructors_and_des">Class
        scope constructors and destructor</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html">boost/python/stl_iterator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterato">Class
        template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat0">Class
        template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
        constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat1">Class
        template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
        modifiers</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat2">Class
        template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
        observers</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html">boost/python/wrapper.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override">Class
        <code class="computeroutput"><span class="identifier">override</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override_observer_function">Class
        <code class="computeroutput"><span class="identifier">override</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper">Class
        template <code class="computeroutput"><span class="identifier">wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper_observer_">Class
        template <code class="computeroutput"><span class="identifier">wrapper</span></code> observer
        functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.example">Example</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_class_hpp"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp" title="boost/python/class.hpp">boost/python/class.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel">Class
        template <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Bases</span><span class="special">,</span> <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">NonCopyable</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn">Class
        template bases&lt;T1, T2, ...TN&gt;</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_class_hpp.introduction"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
          <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
          defines the interface through which users expose their C++ classes to Python.
          It declares the <code class="computeroutput"><span class="identifier">class_</span></code>
          class template, which is parameterized on the class type being exposed.
          It also exposes the <code class="computeroutput"><span class="identifier">init</span></code>,
          <code class="computeroutput"><span class="identifier">optional</span></code> and <code class="computeroutput"><span class="identifier">bases</span></code> utility class templates, which
          are used in conjunction with <code class="computeroutput"><span class="identifier">class_</span></code>.
        </p>
<p>
          <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">class_fwd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code> contains a forward declaration of the
          <code class="computeroutput"><span class="identifier">class_</span></code> class template.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">Class
        template <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Bases</span><span class="special">,</span> <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">NonCopyable</span><span class="special">&gt;</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.heldtype_semantics">HeldType
          Semantics</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_synopsis">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> synopsis</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_constructor">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> modifier
          functions</a></span></dt>
</dl></div>
<p>
          Creates a Python class associated with the C++ type passed as its first
          parameter. Although it has four template parameters, only the first one
          is required. The three optional arguments can actually be supplied <span class="bold"><strong>in any order</strong></span>; Boost.Python determines the role of
          the argument from its type.
        </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Template Parameter
                  </p>
                </th>
<th>
                  <p>
                    Requirements
                  </p>
                </th>
<th>
                  <p>
                    Semantics
                  </p>
                </th>
<th>
                  <p>
                    Default
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </td>
<td>
                  <p>
                    A class type.
                  </p>
                </td>
<td>
                  <p>
                    The class being wrapped
                  </p>
                </td>
<td>
                </td>
</tr>
<tr>
<td>
                  <p>
                    Bases
                  </p>
                </td>
<td>
                  <p>
                    A specialization of <a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn" title="Class template bases&lt;T1, T2, ...TN&gt;">bases&lt;...&gt;</a>
                    which specifies previously-exposed C++ base classes of <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    Registers <code class="computeroutput"><span class="identifier">from_python</span></code>
                    conversions from wrapped <code class="computeroutput"><span class="identifier">T</span></code>
                    instances to each of its exposed direct and indirect bases. For
                    each polymorphic base <code class="computeroutput"><span class="identifier">B</span></code>,
                    registers conversions from indirectly-held wrapped <code class="computeroutput"><span class="identifier">B</span></code> instances to <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    <a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn" title="Class template bases&lt;T1, T2, ...TN&gt;">bases&lt;&gt;</a>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    HeldType
                  </p>
                </td>
<td>
                  <p>
                    Must be <code class="computeroutput"><span class="identifier">T</span></code>, a
                    class derived from <code class="computeroutput"><span class="identifier">T</span></code>,
                    or a <a class="link" href="concepts/dereferenceable.html#concepts.dereferenceable.concept_requirements" title="Concept Requirements">Dereferenceable</a>
                    type for which <code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">HeldType</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
                    is <code class="computeroutput"><span class="identifier">T</span></code> or a class
                    derived from <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    Specifies the type that is actually embedded in a Python object
                    wrapping a <code class="computeroutput"><span class="identifier">T</span></code>
                    instance when <code class="computeroutput"><span class="identifier">T</span></code>'s
                    constructor is called or when a <code class="computeroutput"><span class="identifier">T</span></code>
                    or <code class="computeroutput"><span class="identifier">T</span><span class="special">*</span></code>
                    is converted to Python without the use of <a class="link" href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions" title="Functions">ptr</a>,
                    <code class="computeroutput"><span class="identifier">ref</span></code>, or <a class="link" href="concepts.html#concepts.callpolicies" title="CallPolicies">Call Policies</a> such as
                    <a class="link" href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_internal_ref.class_template_return_internal_r" title="Class template return_internal_reference">return_internal_reference</a>.
                    More details below.
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    NonCopyable
                  </p>
                </td>
<td>
                  <p>
                    If supplied, must be <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    Suppresses automatic registration of <code class="computeroutput"><span class="identifier">to_python</span></code>
                    conversions which copy <code class="computeroutput"><span class="identifier">T</span></code>
                    instances. Required when <code class="computeroutput"><span class="identifier">T</span></code>
                    has no publicly-accessible copy constructor.
                  </p>
                </td>
<td>
                  <p>
                    An unspecified type other than boost::noncopyable.
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.heldtype_semantics"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.heldtype_semantics" title="HeldType Semantics">HeldType
          Semantics</a>
</h4></div></div></div>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
                If HeldType is derived from <code class="computeroutput"><span class="identifier">T</span></code>,
                its exposed constructor(s) must accept an initial <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code> argument which refers back to the
                Python object that contains the HeldType instance, as shown in this
                example. This argument is not included in the <a class="link" href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">init-expression</a>
                passed to <a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu" title="Class template class_ modifier functions">def(init_expr)</a>,
                below, nor is it passed explicitly by users when Python instances
                of <code class="computeroutput"><span class="identifier">T</span></code> are created.
                This idiom allows C++ virtual functions which will be overridden
                in Python to access the Python object so the Python method can be
                invoked. Boost.Python automatically registers additional converters
                which allow wrapped instances of <code class="computeroutput"><span class="identifier">T</span></code>
                to be passed to wrapped C++ functions expecting HeldType arguments.
              </li>
<li class="listitem">
                Because Boost.Python will always allow wrapped instances of <code class="computeroutput"><span class="identifier">T</span></code> to be passed in place of HeldType
                arguments, specifying a smart pointer for HeldType allows users to
                pass Python <code class="computeroutput"><span class="identifier">T</span></code> instances
                where a smart pointer-to-T is expected. Smart pointers such as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">auto_ptr</span><span class="special">&lt;&gt;</span></code>
                or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;&gt;</span></code>
                which contain a nested type <code class="computeroutput"><span class="identifier">element_type</span></code>
                designating the referent type are automatically supported; additional
                smart pointer types can be supported by specializing <code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">HeldType</span><span class="special">&gt;</span></code>.
              </li>
<li class="listitem">
                As in case 1 above, when HeldType is a smart pointer to a class derived
                from <code class="computeroutput"><span class="identifier">T</span></code>, the initial
                <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
                argument must be supplied by all of HeldType's exposed constructors.
              </li>
<li class="listitem">
                Except in cases 1 and 3, users may optionally specify that T itself
                gets initialized with a similar initial <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code> argument by specializing <a class="link" href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc" title="Class template has_back_reference">has_back_reference&lt;T&gt;</a>.
              </li>
</ol></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_synopsis"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_synopsis" title="Class template class_ synopsis">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span>
    <span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Bases</span> <span class="special">=</span> <span class="identifier">bases</span><span class="special">&lt;&gt;</span>
          <span class="special">,</span> <span class="keyword">class</span> <span class="identifier">HeldType</span> <span class="special">=</span> <span class="identifier">T</span>
          <span class="special">,</span> <span class="keyword">class</span> <span class="identifier">NonCopyable</span> <span class="special">=</span> <span class="identifier">unspecified</span>
         <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">class_</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
  <span class="comment">// Constructors with default __init__</span>
  <span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">);</span>
  <span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">docstring</span><span class="special">);</span>

  <span class="comment">// Constructors, specifying non-default __init__</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Init</span><span class="special">);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">Init</span><span class="special">);</span>

  <span class="comment">// Exposing additional __init__ functions</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="identifier">Init</span><span class="special">);</span>

  <span class="comment">// defining methods</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A3</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A3</span> <span class="keyword">const</span><span class="special">&amp;);</span>

  <span class="comment">// declaring method as static</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">staticmethod</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">);</span>

  <span class="comment">// exposing operators</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">operator_</span><span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;);</span>

  <span class="comment">// Raw attribute modification</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">setattr</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;);</span>

  <span class="comment">// exposing data members</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readonly</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">);</span>

  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readwrite</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">);</span>

  <span class="comment">// exposing static data members</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readonly</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
  <span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readwrite</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>

  <span class="comment">// property creation</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">&gt;</span>
  <span class="keyword">void</span> <span class="identifier">add_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Set</span><span class="special">&gt;</span>
  <span class="keyword">void</span> <span class="identifier">add_property</span><span class="special">(</span>
      <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="identifier">Set</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fset</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>

  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">&gt;</span>
  <span class="keyword">void</span> <span class="identifier">add_static_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">);</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Set</span><span class="special">&gt;</span>
  <span class="keyword">void</span> <span class="identifier">add_static_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="identifier">Set</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fset</span><span class="special">);</span>

  <span class="comment">// pickle support</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">PickleSuite</span><span class="special">&gt;</span>
  <span class="identifier">self</span><span class="special">&amp;</span> <span class="identifier">def_pickle</span><span class="special">(</span><span class="identifier">PickleSuite</span> <span class="keyword">const</span><span class="special">&amp;);</span>
  <span class="identifier">self</span><span class="special">&amp;</span> <span class="identifier">enable_pickling</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_constructor"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_constructor" title="Class template class_ constructors">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> constructors</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">docstring</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Init</span> <span class="identifier">init_spec</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">Init</span> <span class="identifier">init_spec</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>. If docstring is supplied, it must be an
                  <a class="link" href="glossary.html#ntbs">ntbs</a>. If <code class="computeroutput"><span class="identifier">init_spec</span></code>
                  is supplied, it must be either the special enumeration constant
                  <code class="computeroutput"><span class="identifier">no_init</span></code> or an
                  <a class="link" href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">init-expression</a>
                  compatible with <code class="computeroutput"><span class="identifier">T</span></code>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<p>
                  Constructs a <code class="computeroutput"><span class="identifier">class_</span></code>
                  object holding a Boost.Python extension class named name. The named
                  attribute of the <a class="link" href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction" title="Introduction">current
                  scope</a> is bound to the new extension class.
                </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      If supplied, the value of docstring is bound to the <code class="computeroutput"><span class="identifier">__doc__</span></code> attribute of the
                      extension class.
                    </li>
<li class="listitem">
                      If <code class="computeroutput"><span class="identifier">init_spec</span></code>
                      is <code class="computeroutput"><span class="identifier">no_init</span></code>,
                      a special <code class="computeroutput"><span class="identifier">__init__</span></code>
                      function is generated which always raises a Python exception.
                      Otherwise, <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init_spec</span><span class="special">)</span></code> is called.
                    </li>
<li class="listitem">
                      If <code class="computeroutput"><span class="identifier">init_spec</span></code>
                      is not supplied, <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;&gt;())</span></code> is called.
                    </li>
</ul></div>
</dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allowing the user to specify constructor arguments in the <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;&gt;</span></code>
                  constructor helps her to avoid the common run-time errors which
                  result from invoking wrapped member functions without having exposed
                  an <code class="computeroutput"><span class="identifier">__init__</span></code> function
                  which creates the requisite <code class="computeroutput"><span class="identifier">T</span></code>
                  instance. Types which are not default-constructible will cause
                  a compile-time error unless <code class="computeroutput"><span class="identifier">Init</span></code>
                  is supplied. The user must always supply name as there is currently
                  no portable method to derive the text of the class name from its
                  type.
                </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu" title="Class template class_ modifier functions">Class
          template <code class="computeroutput"><span class="identifier">class_</span></code> modifier
          functions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Init</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="identifier">Init</span> <span class="identifier">init_expr</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="identifier">init_expr</span></code> is the
                  result of an <a class="link" href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">init-expression</a>
                  compatible with <code class="computeroutput"><span class="identifier">T</span></code>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  For each <a class="link" href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">valid
                  prefix</a> <code class="computeroutput"><span class="identifier">P</span></code>
                  of <code class="computeroutput"><span class="identifier">Init</span></code>, adds an
                  <code class="computeroutput"><span class="identifier">__init__</span><span class="special">(...)</span></code>
                  function overload to the extension class accepting P as arguments.
                  Each overload generated constructs an object of HeldType according
                  to the semantics described above, using a copy of init_expr's call
                  policies. If the longest <a class="link" href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">valid
                  prefix</a> of Init contains N types and init_expr holds M keywords,
                  an initial sequence of the keywords are used for all but the first
                  N - M arguments of each overload.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allows users to easily expose a class' constructor to Python.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a2</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A3</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a2</span><span class="special">,</span> <span class="identifier">A3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a3</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd>
<p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>. * If a1 is the result of an <a class="link" href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">overload-dispatch-expression</a>,
                  only the second form is allowed and fn must be a pointer to function
                  or pointer to member function whose <a class="link" href="glossary.html#arity">arity</a>
                  is the same as A1's <a class="link" href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">maximum
                  arity</a>.
                </p>
<p>
                  <span class="bold"><strong>Effects:</strong></span> For each prefix <code class="computeroutput"><span class="identifier">P</span></code> of <code class="computeroutput"><span class="identifier">Fn</span></code>'s
                  sequence of argument types, beginning with the one whose length
                  is <code class="computeroutput"><span class="identifier">A1</span></code>'s <a class="link" href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">minimum
                  arity</a>, adds a <code class="computeroutput"><span class="identifier">name</span><span class="special">(...)</span></code> method overload to the extension
                  class. Each overload generated invokes a1's call-expression with
                  <code class="computeroutput"><span class="identifier">P</span></code>, using a copy
                  of a1's call policies. If the longest valid prefix of <code class="computeroutput"><span class="identifier">A1</span></code> contains <code class="computeroutput"><span class="identifier">N</span></code>
                  types and a1 holds <code class="computeroutput"><span class="identifier">M</span></code>
                  keywords, an initial sequence of the keywords are used for all
                  but the first <code class="computeroutput"><span class="identifier">N</span> <span class="special">-</span> <span class="identifier">M</span></code>
                  arguments of each overload.
                </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
                      Otherwise, a single method overload is built around fn, which
                      must not be null:
                      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
                            If fn is a function pointer, its first argument must
                            be of the form U, U cv&amp;, U cv*, or U cv* const&amp;,
                            where T* is convertible to U*, and a1-a3, if supplied,
                            may be selected in any order from the table below.
                          </li>
<li class="listitem">
                            Otherwise, if fn is a member function pointer, its target
                            must be T or one of its public base classes, and a1-a3,
                            if supplied, may be selected in any order from the table
                            below.
                          </li>
<li class="listitem">
<p class="simpara">
                            Otherwise, Fn must be [derived from] <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object">object</a>,
                            and a1-a2, if supplied, may be selcted in any order from
                            the first two rows of the table below. To be useful,
                            fn should be <a href="http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-6" target="_top">callable</a>.
                          </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                                    <p>
                                      Mnemonic Name
                                    </p>
                                  </th>
<th>
                                    <p>
                                      Requirements/Type properties
                                    </p>
                                  </th>
<th>
                                    <p>
                                      Effects
                                    </p>
                                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                                    <p>
                                      docstring
                                    </p>
                                  </td>
<td>
                                    <p>
                                      Any <a class="link" href="glossary.html#ntbs">ntbs</a>
                                    </p>
                                  </td>
<td>
                                    <p>
                                      Value will be bound to the __doc__ attribute
                                      of the resulting method overload. If an earlier
                                      overload supplied a docstring, two newline
                                      characters and the new docstring are appended
                                      to it.
                                    </p>
                                  </td>
</tr>
<tr>
<td>
                                    <p>
                                      policies
                                    </p>
                                  </td>
<td>
                                    <p>
                                      A model of <a class="link" href="concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
                                    </p>
                                  </td>
<td>
                                    <p>
                                      A copy will be used as the call policies of
                                      the resulting method overload.
                                    </p>
                                  </td>
</tr>
<tr>
<td>
                                    <p>
                                      keywords
                                    </p>
                                  </td>
<td>
                                    <p>
                                      The result of a <a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expression</a>
                                      specifying no more arguments than the <a class="link" href="glossary.html#arity">arity</a> of fn.
                                    </p>
                                  </td>
<td>
                                    <p>
                                      A copy will be used as the call policies of
                                      the resulting method overload.
                                    </p>
                                  </td>
</tr>
</tbody>
</table></div>
</li>
</ul></div>
                    </li></ul></div>
</dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">staticmethod</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>, and corresponds to a method whose overloads
                  have all been defined.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Replaces the existing named attribute <code class="computeroutput"><span class="identifier">x</span></code>
                  with the result of invoking <code class="computeroutput"><span class="identifier">staticmethod</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> in Python. Specifies that the
                  corresponding method is static and therefore no object instance
                  will be passed to it. This is equivalent to the Python statement:
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">setattr</span><span class="special">(</span><span class="identifier">self</span><span class="special">,</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">staticmethod</span><span class="special">(</span><span class="identifier">getattr</span><span class="special">(</span><span class="identifier">self</span><span class="special">,</span> <span class="identifier">name</span><span class="special">)))</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Note</span></dt>
<dd><p>
                  Attempting to invoke def(name,...) after invoking staticmethod(name)
                  will <a class="link" href="glossary.html#raise">raise</a> a RuntimeError.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">operator_</span><span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Adds a Python <a href="http://www.python.org/doc/ref/specialnames.html" target="_top">special
                  method</a> as described <a class="link" href="high_level_components/boost_python_operators_hpp.html" title="boost/python/operators.hpp">here</a>.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">setattr</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">u</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<p>
                  Converts <code class="computeroutput"><span class="identifier">u</span></code> to Python
                  and adds it to the attribute dictionary of the extension class:
                </p>
<pre class="programlisting"><span class="identifier">PyObject_SetAttrString</span><span class="special">(</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">ptr</span><span class="special">(),</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">object</span><span class="special">(</span><span class="identifier">u</span><span class="special">).</span><span class="identifier">ptr</span><span class="special">());</span></pre>
</dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">add_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Set</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">add_property</span><span class="special">(</span>
      <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="identifier">Set</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fset</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conform to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Creates a new Python <a href="http://www.python.org/2.2.2/descrintro.html#property" target="_top">property</a>
                  class instance, passing <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">fget</span><span class="special">)</span></code> (and <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">fset</span><span class="special">)</span></code> in the second form) with an (optional)
                  docstring <code class="computeroutput"><span class="identifier">doc</span></code> to
                  its constructor, then adds that property to the Python class object
                  under construction with the given attribute name.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allows users to easily expose functions that can be invoked from
                  Python with attribute access syntax.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">add_static_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Get</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Set</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">add_static_property</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Get</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fget</span><span class="special">,</span> <span class="identifier">Set</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">fset</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Creates a Boost.Python.StaticProperty object, passing <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">fget</span><span class="special">)</span></code>
                  (and <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">fset</span><span class="special">)</span></code>
                  in the second form) to its constructor, then adds that property
                  to the Python class under construction with the given attribute
                  name. StaticProperty is a special subclass of Python's property
                  class which can be called without an initial self argument.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allows users to easily expose functions that can be invoked from
                  Python with static attribute access syntax.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readonly</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readonly</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  name is an <a class="link" href="glossary.html#ntbs">ntbs</a> which conforms to Python's
                  <a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
                  naming rules</a>. <code class="computeroutput"><span class="identifier">doc</span></code>
                  is also an <a class="link" href="glossary.html#ntbs">ntbs</a>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<pre class="programlisting"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">add_property</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">pm</span><span class="special">),</span> <span class="identifier">doc</span><span class="special">);</span></pre>
<p>
                  and
                </p>
<pre class="programlisting"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">add_static_property</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">d</span><span class="special">));</span></pre>
<p>
                  respectively.
                </p>
</dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allows users to easily expose a class' data member or free variable
                  such that it can be inspected from Python with a natural syntax.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readwrite</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_readwrite</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">D</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd>
<pre class="programlisting"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">add_property</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">pm</span><span class="special">),</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">pm</span><span class="special">),</span> <span class="identifier">doc</span><span class="special">);</span></pre>
<p>
                  and
                </p>
<pre class="programlisting"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">add_static_property</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">d</span><span class="special">),</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">d</span><span class="special">));</span></pre>
<p>
                  respectively.
                </p>
</dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Allows users to easily expose a class' data or free variable member
                  such that it can be inspected and set from Python with a natural
                  syntax.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">PickleSuite</span><span class="special">&gt;</span>
<span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">def_pickle</span><span class="special">(</span><span class="identifier">PickleSuite</span> <span class="keyword">const</span><span class="special">&amp;);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                  PickleSuite must be publically derived from <a class="link" href="topics/pickle_support.html#topics.pickle_support.the_pickle_interface" title="The Pickle Interface">pickle_suite</a>.
                </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Defines a legal combination of the special attributes and methods:
                  __getinitargs__, __getstate__, __setstate__, __getstate_manages_dict__,
                  __safe_for_unpickling__, __reduce__
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Provides an <a class="link" href="topics/pickle_support.html#topics.pickle_support.the_pickle_interface" title="The Pickle Interface">easy
                  to use high-level interface</a> for establishing complete <a class="link" href="topics/pickle_support.html#topics.pickle_support.the_pickle_interface" title="The Pickle Interface">pickle support</a>
                  for the wrapped class. The user is protected by compile-time consistency
                  checks.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&amp;</span> <span class="identifier">enable_pickling</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
                  Defines the __reduce__ method and the __safe_for_unpickling__ attribute.
                </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Light-weight alternative to def_pickle(). Enables implementation
                  of pickle support from Python.
                </p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn" title="Class template bases&lt;T1, T2, ...TN&gt;">Class
        template bases&lt;T1, T2, ...TN&gt;</a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn.class_template_bases_synopsis">Class
          template bases synopsis</a></span></dt></dl></div>
<p>
          An MPL sequence which can be used in class_&lt;...&gt; instantiations indicate
          a list of base classes.
        </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn.class_template_bases_synopsis"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn.class_template_bases_synopsis" title="Class template bases synopsis">Class
          template bases synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
  <span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">T1</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">,...</span><span class="identifier">Tn</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">&gt;</span>
  <span class="keyword">struct</span> <span class="identifier">bases</span>
  <span class="special">{};</span>
<span class="special">}}</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_class_hpp.examples"></a><a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
          Given a C++ class declaration:
        </p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">Foo</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Bar</span><span class="special">,</span> <span class="keyword">public</span> <span class="identifier">Baz</span>
<span class="special">{</span>
 <span class="keyword">public</span><span class="special">:</span>
   <span class="identifier">Foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">y</span><span class="special">);</span>
   <span class="identifier">Foo</span><span class="special">(</span><span class="keyword">double</span><span class="special">);</span>

   <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">name</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">m_name</span><span class="special">;</span> <span class="special">}</span>
   <span class="keyword">void</span> <span class="identifier">name</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*);</span>

   <span class="keyword">double</span> <span class="identifier">value</span><span class="special">;</span> <span class="comment">// public data</span>
 <span class="keyword">private</span><span class="special">:</span>
   <span class="special">...</span>
<span class="special">};</span>
</pre>
<p>
          A corresponding Boost.Python extension class can be created with:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>

<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Foo</span><span class="special">,</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">Bar</span><span class="special">,</span><span class="identifier">Baz</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"Foo"</span><span class="special">,</span>
          <span class="string">"This is Foo's docstring."</span>
          <span class="string">"It describes our Foo extension class"</span><span class="special">,</span>

          <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span><span class="string">"y"</span><span class="special">),</span> <span class="string">"__init__ docstring"</span><span class="special">)</span>
          <span class="special">)</span>
   <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;())</span>
   <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get_name"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">get_name</span><span class="special">,</span> <span class="identifier">return_internal_reference</span><span class="special">&lt;&gt;())</span>
   <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set_name"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">set_name</span><span class="special">)</span>
   <span class="special">.</span><span class="identifier">def_readwrite</span><span class="special">(</span><span class="string">"value"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">value</span><span class="special">);</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="concepts/objectwrapper.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="high_level_components/boost_python_def_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>
